//
//  HomeBatteryView.m
//  Ginix
//
//  Created by 冯志强 on 2025/3/5.
//

#import "HomeBatteryView.h"

@interface HomeBatteryView()
@property (nonatomic,strong) UIImageView * iconView;
@property (nonatomic,strong) UILabel * infoLabel;
@end

@implementation HomeBatteryView

-(instancetype)initWithFrame:(CGRect)frame{
    
    if (self = [super initWithFrame:frame]) {
        [self setSubViewLayout];
    }
    return self;
    
}
-(void)setSubViewLayout{
    
    [self addSubview:self.iconView];
    [self addSubview:self.infoLabel];
    
}

-(void)setBattery:(NSInteger)battery{
    
    if (battery == 101) {
        self.iconView.image = [UIImage imageNamed:@"Home_battery_chong"];
        self.infoLabel.hidden = YES;
    }else{
        self.infoLabel.text = [NSString stringWithFormat:@"%ld%%",battery];
        self.infoLabel.hidden = NO;
        if (battery > 80) {
            self.iconView.image = [UIImage imageNamed:@"Home_battery_man"];
        }else if (battery <= 80 && battery > 50){
            self.iconView.image = [UIImage imageNamed:@"Home_battery_lv"];
        }else if (battery <= 50 && battery > 20){
            self.iconView.image = [UIImage imageNamed:@"Home_battery_huang"];
        }else {
            self.iconView.image = [UIImage imageNamed:@"Home_battery_hong"];
        }
    }
}

-(UIImageView *)iconView{
    
    if (!_iconView) {
        _iconView = [[UIImageView alloc]initWithFrame:CGRectMake(0, (self.getHeight - 10 * FMScaleX) / 2, 18 * FMScaleX, 10 * FMScaleX)];
    }
    return _iconView;
}
-(UILabel *)infoLabel{
    
    if (!_infoLabel) {
        _infoLabel = [[UILabel alloc]initWithFrame:CGRectMake(GETMaxX(self.iconView) + 4 * FMScaleX, 0, 30 * FMScaleX, 22 * FMScaleX)];
        _infoLabel.font = Regular(12);
        _infoLabel.textColor = RDRGB(0x999999);
    }
    return _infoLabel;
}

@end
